if(NOT EXISTS "@CMAKE_CURRENT_SOURCE_DIR@/nginx-1.14.0.tar.gz" AND NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/nginx-1.14.0")
  message(FATAL_ERROR "Cannot find nginx")
endif()

if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/nginx-1.14.0")
    exec_program(
      "@CMAKE_COMMAND@" ARGS "-E tar xvz \"@CMAKE_CURRENT_SOURCE_DIR@/nginx-1.14.0.tar.gz\""
      RETURN_VALUE rm_retval
    )
    if(NOT "${rm_retval}" STREQUAL 0)
      message(FATAL_ERROR "Problem when tar xvz \"@CMAKE_CURRENT_SOURCE_DIR@/nginx-1.14.0.tar.gz\"")
    else()
      exec_program( 
        "@CMAKE_COMMAND@" ARGS "-E chdir \"@CMAKE_CURRENT_BINARY_DIR@/nginx-1.14.0\" \"./configure\" \"--prefix=@CMAKE_BINARY_DIR@/output/nginxd\""
        RETURN_VALUE rm_retval
      )
      if(NOT "${rm_retval}" STREQUAL 0)
            message(FATAL_ERROR "Problem when ./configure")
      endif()
    endif()
endif()